

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>argoverse.map_representation.map_viz_helper &mdash; argoverse  documentation</title>
  

  
  
  
  

  
  <script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
        <script type="text/javascript" src="../../../_static/jquery.js"></script>
        <script type="text/javascript" src="../../../_static/underscore.js"></script>
        <script type="text/javascript" src="../../../_static/doctools.js"></script>
        <script type="text/javascript" src="../../../_static/language_data.js"></script>
    
    <script type="text/javascript" src="../../../_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/graphviz.css" type="text/css" />
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../../../index.html" class="icon icon-home"> argoverse
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <!-- Local TOC -->
              <div class="local-toc"></div>
            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../index.html">argoverse</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../../index.html">Docs</a> &raquo;</li>
        
          <li><a href="../../index.html">Module code</a> &raquo;</li>
        
      <li>argoverse.map_representation.map_viz_helper</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for argoverse.map_representation.map_viz_helper</h1><div class="highlight"><pre>
<span></span><span class="c1"># &lt;Copyright 2019, Argo AI, LLC. Released under the MIT license.&gt;</span>
<span class="sd">&quot;&quot;&quot;Map visualization helper functions.&quot;&quot;&quot;</span>
<span class="kn">import</span> <span class="nn">copy</span>
<span class="kn">import</span> <span class="nn">math</span>
<span class="kn">import</span> <span class="nn">warnings</span>
<span class="kn">from</span> <span class="nn">typing</span> <span class="k">import</span> <span class="n">Mapping</span><span class="p">,</span> <span class="n">Tuple</span>

<span class="kn">import</span> <span class="nn">cv2</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">from</span> <span class="nn">argoverse.utils.cv2_plotting_utils</span> <span class="k">import</span> <span class="n">draw_polygon_cv2</span><span class="p">,</span> <span class="n">draw_polyline_cv2</span>
<span class="kn">from</span> <span class="nn">argoverse.utils.datetime_utils</span> <span class="k">import</span> <span class="n">generate_datetime_string</span>
<span class="kn">from</span> <span class="nn">argoverse.utils.mesh_grid</span> <span class="k">import</span> <span class="n">get_mesh_grid_as_point_cloud</span>
<span class="kn">from</span> <span class="nn">argoverse.utils.se2</span> <span class="k">import</span> <span class="n">SE2</span>
<span class="kn">from</span> <span class="nn">colour</span> <span class="k">import</span> <span class="n">Color</span>
<span class="kn">from</span> <span class="nn">typing_extensions</span> <span class="k">import</span> <span class="n">Protocol</span>

<span class="kn">from</span> <span class="nn">.lane_segment</span> <span class="k">import</span> <span class="n">LaneSegment</span>

<span class="n">__all__</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;render_global_city_map_bev&quot;</span><span class="p">]</span>

<span class="n">LaneCenterline</span> <span class="o">=</span> <span class="n">Mapping</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="n">LaneSegment</span><span class="p">]</span>


<span class="k">def</span> <span class="nf">_find_min_coords_das</span><span class="p">(</span>
    <span class="n">driveable_areas</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">xmin</span><span class="p">:</span> <span class="nb">float</span><span class="p">,</span> <span class="n">ymin</span><span class="p">:</span> <span class="nb">float</span><span class="p">,</span> <span class="n">xmax</span><span class="p">:</span> <span class="nb">float</span><span class="p">,</span> <span class="n">ymax</span><span class="p">:</span> <span class="nb">float</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Tuple</span><span class="p">[</span><span class="nb">float</span><span class="p">,</span> <span class="nb">float</span><span class="p">,</span> <span class="nb">float</span><span class="p">,</span> <span class="nb">float</span><span class="p">]:</span>
    <span class="k">for</span> <span class="n">da</span> <span class="ow">in</span> <span class="n">driveable_areas</span><span class="p">:</span>
        <span class="n">xmin</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">da</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">min</span><span class="p">(),</span> <span class="n">xmin</span><span class="p">)</span>
        <span class="n">ymin</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">da</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">min</span><span class="p">(),</span> <span class="n">ymin</span><span class="p">)</span>
        <span class="n">xmax</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">da</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">max</span><span class="p">(),</span> <span class="n">xmax</span><span class="p">)</span>
        <span class="n">ymax</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">da</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">max</span><span class="p">(),</span> <span class="n">ymax</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">xmin</span><span class="p">,</span> <span class="n">ymin</span><span class="p">,</span> <span class="n">xmax</span><span class="p">,</span> <span class="n">ymax</span>


<span class="k">def</span> <span class="nf">_find_min_coords_centerlines</span><span class="p">(</span>
    <span class="n">lane_centerlines</span><span class="p">:</span> <span class="n">LaneCenterline</span><span class="p">,</span> <span class="n">xmin</span><span class="p">:</span> <span class="nb">float</span><span class="p">,</span> <span class="n">ymin</span><span class="p">:</span> <span class="nb">float</span><span class="p">,</span> <span class="n">xmax</span><span class="p">:</span> <span class="nb">float</span><span class="p">,</span> <span class="n">ymax</span><span class="p">:</span> <span class="nb">float</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Tuple</span><span class="p">[</span><span class="nb">float</span><span class="p">,</span> <span class="nb">float</span><span class="p">,</span> <span class="nb">float</span><span class="p">,</span> <span class="nb">float</span><span class="p">]:</span>
    <span class="k">for</span> <span class="n">lane_id</span><span class="p">,</span> <span class="n">lane_obj</span> <span class="ow">in</span> <span class="n">lane_centerlines</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
        <span class="n">centerline_2d</span> <span class="o">=</span> <span class="n">lane_obj</span><span class="o">.</span><span class="n">centerline</span>
        <span class="n">xmin</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">centerline_2d</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">min</span><span class="p">(),</span> <span class="n">xmin</span><span class="p">)</span>
        <span class="n">ymin</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">centerline_2d</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">min</span><span class="p">(),</span> <span class="n">ymin</span><span class="p">)</span>
        <span class="n">xmax</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">centerline_2d</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">max</span><span class="p">(),</span> <span class="n">xmax</span><span class="p">)</span>
        <span class="n">ymax</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">centerline_2d</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">max</span><span class="p">(),</span> <span class="n">ymax</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">xmin</span><span class="p">,</span> <span class="n">ymin</span><span class="p">,</span> <span class="n">xmax</span><span class="p">,</span> <span class="n">ymax</span>


<span class="k">def</span> <span class="nf">_get_opencv_green_to_red_colormap</span><span class="p">(</span><span class="n">num_color_bins</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;Create a red to green BGR colormap with a finite number of steps.</span>

<span class="sd">    Args:</span>
<span class="sd">        num_color_bins: Number of color steps</span>

<span class="sd">    Returns:</span>
<span class="sd">        The colormap</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">color_range</span> <span class="o">=</span> <span class="n">Color</span><span class="p">(</span><span class="s2">&quot;green&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">range_to</span><span class="p">(</span><span class="n">Color</span><span class="p">(</span><span class="s2">&quot;red&quot;</span><span class="p">),</span> <span class="n">num_color_bins</span><span class="p">)</span>
    <span class="n">colors_arr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="n">color</span><span class="o">.</span><span class="n">rgb</span><span class="p">]</span> <span class="k">for</span> <span class="n">color</span> <span class="ow">in</span> <span class="n">color_range</span><span class="p">])</span><span class="o">.</span><span class="n">squeeze</span><span class="p">()</span>
    <span class="c1"># RGB -&gt; BGR for OpenCV&#39;s sake</span>
    <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">fliplr</span><span class="p">(</span><span class="n">colors_arr</span><span class="p">)</span>


<span class="k">def</span> <span class="nf">_get_int_image_bounds_from_city_coords</span><span class="p">(</span>
    <span class="n">driveable_areas</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">lane_centerlines</span><span class="p">:</span> <span class="n">LaneCenterline</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Tuple</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">,</span> <span class="nb">int</span><span class="p">]:</span>
    <span class="sd">&quot;&quot;&quot;Get the internal iamge bounds based on the city coordinates</span>

<span class="sd">    Args:</span>
<span class="sd">        driveable_areas: Driveable area data</span>
<span class="sd">        lane_centerlines: Line centerline data</span>

<span class="sd">    Returns:</span>
<span class="sd">        A tuple containing: image height, image width, and x and y coordinate bounds.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">xmin</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="s2">&quot;inf&quot;</span><span class="p">)</span>
    <span class="n">ymin</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="s2">&quot;inf&quot;</span><span class="p">)</span>
    <span class="n">xmax</span> <span class="o">=</span> <span class="o">-</span><span class="nb">float</span><span class="p">(</span><span class="s2">&quot;inf&quot;</span><span class="p">)</span>
    <span class="n">ymax</span> <span class="o">=</span> <span class="o">-</span><span class="nb">float</span><span class="p">(</span><span class="s2">&quot;inf&quot;</span><span class="p">)</span>

    <span class="n">xmin</span><span class="p">,</span> <span class="n">ymin</span><span class="p">,</span> <span class="n">xmax</span><span class="p">,</span> <span class="n">ymax</span> <span class="o">=</span> <span class="n">_find_min_coords_das</span><span class="p">(</span><span class="n">driveable_areas</span><span class="p">,</span> <span class="n">xmin</span><span class="p">,</span> <span class="n">ymin</span><span class="p">,</span> <span class="n">xmax</span><span class="p">,</span> <span class="n">ymax</span><span class="p">)</span>
    <span class="n">xmin</span><span class="p">,</span> <span class="n">ymin</span><span class="p">,</span> <span class="n">xmax</span><span class="p">,</span> <span class="n">ymax</span> <span class="o">=</span> <span class="n">_find_min_coords_centerlines</span><span class="p">(</span><span class="n">lane_centerlines</span><span class="p">,</span> <span class="n">xmin</span><span class="p">,</span> <span class="n">ymin</span><span class="p">,</span> <span class="n">xmax</span><span class="p">,</span> <span class="n">ymax</span><span class="p">)</span>

    <span class="n">xmin</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">math</span><span class="o">.</span><span class="n">floor</span><span class="p">(</span><span class="n">xmin</span><span class="p">))</span>
    <span class="n">ymin</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">math</span><span class="o">.</span><span class="n">floor</span><span class="p">(</span><span class="n">ymin</span><span class="p">))</span>
    <span class="n">xmax</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">math</span><span class="o">.</span><span class="n">ceil</span><span class="p">(</span><span class="n">xmax</span><span class="p">))</span>
    <span class="n">ymax</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">math</span><span class="o">.</span><span class="n">ceil</span><span class="p">(</span><span class="n">ymax</span><span class="p">))</span>

    <span class="n">im_h</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">math</span><span class="o">.</span><span class="n">ceil</span><span class="p">(</span><span class="n">ymax</span> <span class="o">-</span> <span class="n">ymin</span><span class="p">))</span>
    <span class="n">im_w</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">math</span><span class="o">.</span><span class="n">ceil</span><span class="p">(</span><span class="n">xmax</span> <span class="o">-</span> <span class="n">xmin</span><span class="p">))</span>
    <span class="k">return</span> <span class="n">im_h</span><span class="p">,</span> <span class="n">im_w</span><span class="p">,</span> <span class="n">xmin</span><span class="p">,</span> <span class="n">xmax</span><span class="p">,</span> <span class="n">ymin</span><span class="p">,</span> <span class="n">ymax</span>


<span class="k">class</span> <span class="nc">MapProtocol</span><span class="p">(</span><span class="n">Protocol</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">remove_non_driveable_area_points</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">point_cloud</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span> <span class="n">city_name</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">:</span>
        <span class="o">...</span>


<div class="viewcode-block" id="render_global_city_map_bev"><a class="viewcode-back" href="../../../argoverse.map_representation.html#argoverse.map_representation.map_viz_helper.render_global_city_map_bev">[docs]</a><span class="k">def</span> <span class="nf">render_global_city_map_bev</span><span class="p">(</span>
    <span class="n">lane_centerlines</span><span class="p">:</span> <span class="n">LaneCenterline</span><span class="p">,</span>
    <span class="n">driveable_areas</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">,</span>
    <span class="n">city_name</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span>
    <span class="n">avm</span><span class="p">:</span> <span class="n">MapProtocol</span><span class="p">,</span>
    <span class="n">plot_rasterized_roi</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">,</span>
    <span class="n">plot_vectormap_roi</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
    <span class="n">centerline_color_scheme</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">&quot;constant&quot;</span><span class="p">,</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Assume indegree and outdegree are always less than 7.</span>
<span class="sd">    Since 1 pixel-per meter resolution is very low, we upsample the resolution</span>
<span class="sd">    by some constant factor.</span>

<span class="sd">    Args:</span>
<span class="sd">        lane_centerlines: Line centerline data</span>
<span class="sd">        driveable_areas: Driveable area data</span>
<span class="sd">        city_name: The city name (eg. &quot;PIT&quot;)</span>
<span class="sd">        avm: The map</span>
<span class="sd">        plot_rasterized_roi: Whether to show the rasterized ROI</span>
<span class="sd">        plot_vectormap_roi: Whether to show the vector map ROI</span>
<span class="sd">        centerline_color_scheme: `&quot;indegree&quot;`, `&quot;outdegree&quot;`, or `&quot;constant&quot;`</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">UPSAMPLE_FACTOR</span> <span class="o">=</span> <span class="mi">2</span>
    <span class="n">GRID_NUMBER_INTERVAL</span> <span class="o">=</span> <span class="mi">500</span>
    <span class="n">NUM_COLOR_BINS</span> <span class="o">=</span> <span class="mi">7</span>

    <span class="n">warnings</span><span class="o">.</span><span class="n">filterwarnings</span><span class="p">(</span><span class="s2">&quot;error&quot;</span><span class="p">)</span>
    <span class="n">im_h</span><span class="p">,</span> <span class="n">im_w</span><span class="p">,</span> <span class="n">xmin</span><span class="p">,</span> <span class="n">xmax</span><span class="p">,</span> <span class="n">ymin</span><span class="p">,</span> <span class="n">ymax</span> <span class="o">=</span> <span class="n">_get_int_image_bounds_from_city_coords</span><span class="p">(</span><span class="n">driveable_areas</span><span class="p">,</span> <span class="n">lane_centerlines</span><span class="p">)</span>
    <span class="n">rendered_image</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">ones</span><span class="p">((</span><span class="n">im_h</span> <span class="o">*</span> <span class="n">UPSAMPLE_FACTOR</span><span class="p">,</span> <span class="n">im_w</span> <span class="o">*</span> <span class="n">UPSAMPLE_FACTOR</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span>
    <span class="n">image_to_city_se2</span> <span class="o">=</span> <span class="n">SE2</span><span class="p">(</span><span class="n">rotation</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">eye</span><span class="p">(</span><span class="mi">2</span><span class="p">),</span> <span class="n">translation</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="o">-</span><span class="n">xmin</span><span class="p">,</span> <span class="o">-</span><span class="n">ymin</span><span class="p">]))</span>

    <span class="k">if</span> <span class="n">plot_rasterized_roi</span><span class="p">:</span>
        <span class="n">grid_2d_pts</span> <span class="o">=</span> <span class="n">get_mesh_grid_as_point_cloud</span><span class="p">(</span><span class="n">xmin</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">xmax</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="n">ymin</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">ymax</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span>
        <span class="n">pink</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">180.0</span><span class="p">,</span> <span class="mf">105.0</span><span class="p">,</span> <span class="mf">255.0</span><span class="p">])</span> <span class="o">/</span> <span class="mi">255</span>
        <span class="n">roi_2d_pts</span> <span class="o">=</span> <span class="n">avm</span><span class="o">.</span><span class="n">remove_non_driveable_area_points</span><span class="p">(</span><span class="n">grid_2d_pts</span><span class="p">,</span> <span class="n">city_name</span><span class="p">)</span>
        <span class="n">roi_2d_pts</span> <span class="o">=</span> <span class="n">image_to_city_se2</span><span class="o">.</span><span class="n">transform_point_cloud</span><span class="p">(</span><span class="n">roi_2d_pts</span><span class="p">)</span>
        <span class="n">roi_2d_pts</span> <span class="o">*=</span> <span class="n">UPSAMPLE_FACTOR</span>
        <span class="n">roi_2d_pts</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="n">roi_2d_pts</span><span class="p">)</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">int32</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">pt</span> <span class="ow">in</span> <span class="n">roi_2d_pts</span><span class="p">:</span>
            <span class="n">row</span> <span class="o">=</span> <span class="n">pt</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
            <span class="n">col</span> <span class="o">=</span> <span class="n">pt</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="n">rendered_image</span><span class="p">[</span><span class="n">row</span><span class="p">,</span> <span class="n">col</span><span class="p">,</span> <span class="p">:]</span> <span class="o">=</span> <span class="n">pink</span>

    <span class="k">if</span> <span class="n">plot_vectormap_roi</span><span class="p">:</span>
        <span class="n">driveable_areas</span> <span class="o">=</span> <span class="n">copy</span><span class="o">.</span><span class="n">deepcopy</span><span class="p">(</span><span class="n">driveable_areas</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">da_idx</span><span class="p">,</span> <span class="n">da</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">driveable_areas</span><span class="p">):</span>
            <span class="n">da</span> <span class="o">=</span> <span class="n">image_to_city_se2</span><span class="o">.</span><span class="n">transform_point_cloud</span><span class="p">(</span><span class="n">da</span><span class="p">[:,</span> <span class="p">:</span><span class="mi">2</span><span class="p">])</span>
            <span class="n">rendered_image</span> <span class="o">=</span> <span class="n">draw_polygon_cv2</span><span class="p">(</span><span class="n">da</span> <span class="o">*</span> <span class="n">UPSAMPLE_FACTOR</span><span class="p">,</span> <span class="n">rendered_image</span><span class="p">,</span> <span class="n">pink</span><span class="p">)</span>

    <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">im_w</span> <span class="o">*</span> <span class="n">UPSAMPLE_FACTOR</span><span class="p">,</span> <span class="n">GRID_NUMBER_INTERVAL</span><span class="p">):</span>
        <span class="k">for</span> <span class="n">y</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">im_h</span> <span class="o">*</span> <span class="n">UPSAMPLE_FACTOR</span><span class="p">,</span> <span class="n">GRID_NUMBER_INTERVAL</span><span class="p">):</span>
            <span class="n">coords_str</span> <span class="o">=</span> <span class="n">f</span><span class="s2">&quot;</span><span class="si">{x}</span><span class="s2">_</span><span class="si">{y}</span><span class="s2">&quot;</span>
            <span class="n">cv2</span><span class="o">.</span><span class="n">putText</span><span class="p">(</span>
                <span class="n">rendered_image</span><span class="p">,</span>
                <span class="n">coords_str</span><span class="p">,</span>
                <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">),</span>
                <span class="n">cv2</span><span class="o">.</span><span class="n">FONT_HERSHEY_SIMPLEX</span><span class="p">,</span>
                <span class="mi">1</span><span class="p">,</span>
                <span class="p">(</span><span class="mi">255</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span>
                <span class="mi">2</span><span class="p">,</span>
                <span class="n">cv2</span><span class="o">.</span><span class="n">LINE_AA</span><span class="p">,</span>
                <span class="n">bottomLeftOrigin</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
            <span class="p">)</span>

    <span class="c1"># Color the graph</span>
    <span class="n">max_outdegree</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="n">max_indegree</span> <span class="o">=</span> <span class="mi">0</span>

    <span class="n">colors_arr</span> <span class="o">=</span> <span class="n">_get_opencv_green_to_red_colormap</span><span class="p">(</span><span class="n">NUM_COLOR_BINS</span><span class="p">)</span>

    <span class="n">blue</span> <span class="o">=</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">][::</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
    <span class="k">for</span> <span class="n">lane_id</span><span class="p">,</span> <span class="n">lane_obj</span> <span class="ow">in</span> <span class="n">lane_centerlines</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
        <span class="n">centerline_2d</span> <span class="o">=</span> <span class="n">lane_obj</span><span class="o">.</span><span class="n">centerline</span>
        <span class="n">centerline_2d</span> <span class="o">=</span> <span class="n">image_to_city_se2</span><span class="o">.</span><span class="n">transform_point_cloud</span><span class="p">(</span><span class="n">centerline_2d</span><span class="p">)</span>
        <span class="n">centerline_2d</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="n">centerline_2d</span><span class="p">)</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">int32</span><span class="p">)</span>

        <span class="n">preds</span> <span class="o">=</span> <span class="n">lane_obj</span><span class="o">.</span><span class="n">predecessors</span>
        <span class="n">succs</span> <span class="o">=</span> <span class="n">lane_obj</span><span class="o">.</span><span class="n">successors</span>

        <span class="n">indegree</span> <span class="o">=</span> <span class="mi">0</span> <span class="k">if</span> <span class="n">preds</span> <span class="ow">is</span> <span class="kc">None</span> <span class="k">else</span> <span class="nb">len</span><span class="p">(</span><span class="n">preds</span><span class="p">)</span>
        <span class="n">outdegree</span> <span class="o">=</span> <span class="mi">0</span> <span class="k">if</span> <span class="n">succs</span> <span class="ow">is</span> <span class="kc">None</span> <span class="k">else</span> <span class="nb">len</span><span class="p">(</span><span class="n">succs</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">indegree</span> <span class="o">&gt;</span> <span class="n">max_indegree</span><span class="p">:</span>
            <span class="n">max_indegree</span> <span class="o">=</span> <span class="n">indegree</span>
            <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;max indegree&quot;</span><span class="p">,</span> <span class="n">indegree</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">outdegree</span> <span class="o">&gt;</span> <span class="n">max_outdegree</span><span class="p">:</span>
            <span class="n">max_outdegree</span> <span class="o">=</span> <span class="n">outdegree</span>
            <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;max outdegree&quot;</span><span class="p">,</span> <span class="n">outdegree</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">centerline_color_scheme</span> <span class="o">==</span> <span class="s2">&quot;indegree&quot;</span><span class="p">:</span>
            <span class="n">color</span> <span class="o">=</span> <span class="n">colors_arr</span><span class="p">[</span><span class="n">indegree</span><span class="p">]</span>
        <span class="k">elif</span> <span class="n">centerline_color_scheme</span> <span class="o">==</span> <span class="s2">&quot;outdegree&quot;</span><span class="p">:</span>
            <span class="n">color</span> <span class="o">=</span> <span class="n">colors_arr</span><span class="p">[</span><span class="n">outdegree</span><span class="p">]</span>
        <span class="k">elif</span> <span class="n">centerline_color_scheme</span> <span class="o">==</span> <span class="s2">&quot;constant&quot;</span><span class="p">:</span>
            <span class="n">color</span> <span class="o">=</span> <span class="n">blue</span>

        <span class="n">draw_polyline_cv2</span><span class="p">(</span>
            <span class="n">centerline_2d</span> <span class="o">*</span> <span class="n">UPSAMPLE_FACTOR</span><span class="p">,</span> <span class="n">rendered_image</span><span class="p">,</span> <span class="n">color</span><span class="p">,</span> <span class="n">im_h</span> <span class="o">*</span> <span class="n">UPSAMPLE_FACTOR</span><span class="p">,</span> <span class="n">im_w</span> <span class="o">*</span> <span class="n">UPSAMPLE_FACTOR</span>
        <span class="p">)</span>

    <span class="c1"># provide colormap in corner</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">NUM_COLOR_BINS</span><span class="p">):</span>
        <span class="n">rendered_image</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="n">i</span><span class="p">,</span> <span class="p">:]</span> <span class="o">=</span> <span class="n">colors_arr</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>

    <span class="n">rendered_image</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">flipud</span><span class="p">(</span><span class="n">rendered_image</span><span class="p">)</span>
    <span class="n">rendered_image</span> <span class="o">*=</span> <span class="mi">255</span>
    <span class="n">rendered_image</span> <span class="o">=</span> <span class="n">rendered_image</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">uint8</span><span class="p">)</span>

    <span class="n">cur_datetime</span> <span class="o">=</span> <span class="n">generate_datetime_string</span><span class="p">()</span>
    <span class="n">img_save_fpath</span> <span class="o">=</span> <span class="n">f</span><span class="s2">&quot;</span><span class="si">{city_name}</span><span class="s2">_</span><span class="si">{centerline_color_scheme}</span><span class="s2">_</span><span class="si">{cur_datetime}</span><span class="s2">.png&quot;</span>
    <span class="n">cv2</span><span class="o">.</span><span class="n">imwrite</span><span class="p">(</span><span class="n">filename</span><span class="o">=</span><span class="n">img_save_fpath</span><span class="p">,</span> <span class="n">img</span><span class="o">=</span><span class="n">rendered_image</span><span class="p">)</span>

    <span class="n">warnings</span><span class="o">.</span><span class="n">resetwarnings</span><span class="p">()</span></div>
</pre></div>

           </div>
           
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2019, Argo AI, LLC

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>